// custom-tab-bar/index.js
const app = getApp()
Component({
  data: {
    selected: 0,
    color: '#8a8a8a',
    selectedColor: '#0165ff',
    fontWeight: 'bold',
    list: [
      {
        current: 0,
        pagePath: '/pages/home/index',
        text: '首页',
        iconPath: '/assets/tabbar/dashboard.png',
        selectedIconPath: '/assets/tabbar/dashboard-selected.png'
      },
      {
        current: 1,
        pagePath: '/pages/create/index',
        text: '快速创建',
        bulge: true,
        iconPath: '/assets/tabbar/add.png'
        // "selectedIconPath": "/assets/icon/用户_选中.png"
      },
      {
        current: 2,
        pagePath: '/pages/user-center/index',
        text: '我的',
        iconPath: '/assets/tabbar/user.png',
        selectedIconPath: '/assets/tabbar/user-selected.png'
      }
    ]
  },
  ready: function () {
    this.setData({
      selected: app.globalData.selected
    })
  },
  attached() {},
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      if (data.index == 1) {
        wx.navigateTo({
          url: '/pages/convenient-order/index'
        })

        return
      }

      app.globalData.selected = data.index
      wx.switchTab({ url })
      // this.setData({ selected: data.index })

      console.log('selected', app.globalData.selected)
    }
  }
})
